package lock.demo2;

public class Input implements Runnable{
    private Resource r;
    public Input(Resource r){
        this.r=r;
    }
    private int i=0;
    @Override
    public void run() {
        while (true){
            synchronized (r){
                if(r.flag){
                    try {
                        r.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }

                if(i%2==0){
                    r.name="小马";
                    r.sex="男";
                }else{
                    r.name="wenjing";
                    r.sex="nv";
                }
                r.flag=true;
                r.notify();

                i++;
            }
        }
    }
}
